package com.ddwl.goods.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.AcademyColumnService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.*;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.AcademyColumnEssayVo;
import com.ddwl.schema.vo.goods.AcademyColumnVo;
import com.ddwl.schema.vo.goods.AcademyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author hemiaojun
 * @Date 2020/11/19 16:38
 */
@RestController
@RequestMapping("/academyColumn")
@Api(tags = "商学院文章栏目")
public class AcademyColumnController extends BaseController {

    @Resource
    private AcademyColumnService academyColumnService;

    @PostMapping("/add")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("新增栏目")
    public RestVo add(@Valid @RequestBody AcademyColumnBo bo){
        academyColumnService.add(bo,getUserId());
        return RestVo.ok();
    }

    @PostMapping("/update")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("修改栏目")
    public RestVo update(@Valid @RequestBody AcademyColumnUpdateBo bo){
        academyColumnService.update(bo,getUserId());
        return RestVo.ok();
    }

    @GetMapping("/get/{id}")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("栏目详情")
    public RestVo<AcademyColumnVo> get(@PathVariable("id") String id){
        return RestVo.ok(academyColumnService.get(id));
    }

    @DeleteMapping("/delete/{id}")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("栏目详情")
    public RestVo delete(@PathVariable("id") String id){
        academyColumnService.delete(id,getUserId());
        return RestVo.ok();
    }

    @PostMapping("/page")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("栏目分页")
    public RestVo<PageVo<AcademyColumnVo>> page(@RequestBody PageBo<AcademyColumnBo> pageBo){
        return RestVo.ok(academyColumnService.page(pageBo));
    }

    @GetMapping("/list")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("文章添加至栏目时获取栏目列表")
    public RestVo<List<AcademyColumnVo>> getList(){
        return RestVo.ok(academyColumnService.getList());
    }

    @PostMapping("/effect")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("启用禁用")
    public RestVo effect(@RequestBody AcademyColumnEffectBo bo){
        academyColumnService.effect(bo,getUserId());
        return RestVo.ok();
    }

    @PostMapping("/addEssay")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("添加文章")
    public RestVo addEssay(@Valid @RequestBody AcademyColumnAddEssayBo bo){
        academyColumnService.addEssay(bo);
        return RestVo.ok();
    }


    @GetMapping("/getColumnEssay/{essayId}")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("根据文章id获取文章所属栏目id")
    public RestVo<List<String>> getColumnEssayByEssayId(@PathVariable("essayId") String essayId){
        return RestVo.ok(academyColumnService.getColumnEssayByEssayId(essayId));
    }

    @PostMapping("/deleteEssay")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("移除文章")
    public RestVo deleteEssay(@Valid @RequestBody AcademyColumnDeleteEssayBo bo){
        academyColumnService.deleteEssay(bo);
        return RestVo.ok();
    }


    @GetMapping("/getEssayByColumnId/{columnId}")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("获取栏目下文章")
    public RestVo<List<AcademyVo>> addEssay(@PathVariable("columnId") String columnId){
        return RestVo.ok(academyColumnService.getEssayByColumnId(columnId));
    }


    @PostMapping("/pageColumnEssay")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE,BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.MALL})
    @ApiOperation("获取栏目下文章")
    public RestVo<PageVo<AcademyVo>> getEssayByColumnId(@Valid @RequestBody PageBo<ColumnEssayPageBo> pageBo){
        return RestVo.ok(academyColumnService.pageColumnEssay(pageBo));
    }

    @GetMapping("/getAcademyColumnEssay")
    @Auth(product = {BaseEnum.ProductEnum.FENXIAO, BaseEnum.ProductEnum.MALL})
    @ApiOperation("app获取各栏目以及栏目下文章")
    public RestVo<List<AcademyColumnEssayVo>> getAcademyColumnEssay(){
        return RestVo.ok(academyColumnService.getAcademyColumnEssay());
    }

    @PostMapping("/essaySort")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("栏目下文章排序")
    public RestVo essaySort(@Valid @RequestBody ColumnEssaySortBo bo){
        academyColumnService.essaySort(bo);
        return RestVo.ok();
    }


}
